<template>
  <div>
    <van-goods-action>
      <van-goods-action-icon
        :icon="isCollected ? 'star' : 'star-o'"
        :text="isCollected ? '已收藏' : '未收藏'"
        :color="isCollected ? '#ff5000' : '#666'"
        @click="isCollected = !isCollected"
      />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        :badge="isLogin ? goodsCount : 0"
        @click="$router.push('/cart')"
      />
      <van-goods-action-button type="danger" text="立即购买" />
      <van-goods-action-button
        type="warning"
        text="加入购物车"
        @click="toAddCart"
      />
    </van-goods-action>
  </div>
</template>

<script>
export default {
  props: ["goodsCount"],
  data() {
    return {
      isCollected: true,
      isLogin: false,
    };
  },
  created() {
    let token = localStorage.getItem("token");
    if (token) {
      this.isLogin = true;
    }
  },
  methods: {
    toAddCart() {
      // console.log("点击了加入购物车按钮");
      this.$emit("showSku");
    },
    hdClickCollect() {
      // 判断有没有登录
      // 如果没有登录，提示请先登录，跳转到登录页(/user)
      // let token = localStorage.getItem("token");
      // if(!token){
      //   this.$toast("请先登录！");
      //   setTimeout(()=>{
      //     this.$router.push("/user");
      //   },1000)
      //   return
      // }

      let ret = this.utils.mustBeLogin();
      if (!ret) return;
      this.isCollected = !this.isCollected;
    },
  },
};
</script>
 
<style lang = "less" scoped>
.van-goods-action {
  z-index: 9999;
}
</style>